/**********************************************
** @Author: phy
** @Date:   2017-12-12 14:17:37
** @Last Modified by:   phy
***********************************************/
package controllers

import (
	"fmt"
	//"strconv"
	//"strings"
	//"time"

	//"github.com/astaxie/beego"
	//"WebAdminSys/libs"
	"WebAdminSys/models"
)

type SysControllogController struct {
	BaseController
}

func (self *SysControllogController) GmRecordCtrl() {
	self.Data["pageTitle"] = "点控记录"
	self.display()
}
func (self *SysControllogController) GmRecordCtrlTable() {


	//用户信息
	UserGameID  := self.GetString("UserGameID");
	UserCkind := self.GetString("UserCkind");
	if UserCkind == ""{
		return;
	}

	BeforDateTime := self.GetString("BeforDateTime");
	AfterDateTime := self.GetString("AfterDateTime");
	GMUserName := self.GetString("GMUserName");
	//isabnormal := self.GetString("isabnormal");
	userWinLose := self.GetString("userWinLose");

	//推广号
	strsql := "";
	if UserGameID != ""{
	   	strsql = fmt.Sprintf("%s AND GAMEID = %s",strsql,UserGameID);
	}
		
	if  BeforDateTime != "" {	
		strsql = fmt.Sprintf("%s AND Writedate >= UNIX_TIMESTAMP('%s')",strsql,BeforDateTime);
	}
		
	if  AfterDateTime != "" {
		strsql = fmt.Sprintf("%s AND Writedate <= UNIX_TIMESTAMP('%s')",strsql,AfterDateTime);
	}

	if GMUserName != ""{
		strsql = fmt.Sprintf("%s AND RealName LIKE '%%%s%%'",strsql,GMUserName);
	}

	if userWinLose == "0"{
		strsql = fmt.Sprintf("%s AND NewlCheatRate > 0 ",strsql);
	}
	if userWinLose == "1"{
		strsql = fmt.Sprintf("%s AND NewlCheatRate < 0 ",strsql);
	}

   	if UserCkind == "1" {
	    	//列表
		page, err := self.GetInt("page")
		if err != nil {
			page = 1
		}
		limit, err := self.GetInt("limit")
		if err != nil {
			limit = 30
		}

		self.pageSize = limit



		result, count,_ := models.RecordCtrlData(page,self.pageSize,strsql);
		list := make([]map[string]interface{}, len(result))
		for k, v := range result {
			row := make(map[string]interface{})

			row["ugameID"] = v["GAMEID"]
			row["unickname"] = v["NICKNAME"]
			row["GMUserName"] = v["RealName"];
			row["ctrlTime"] = v["Writedate"]
			row["Userwinlose"] = v["LtotalScore"]
			row["oldrate"] = v["OldlCheatRate"];
			row["newrate"] = v["NewlCheatRate"];
			row["ctrlscore"] = v["NewlCheatLimit"]
			str := fmt.Sprintf("作弊率由%s变为%s,作弊限额由%s变为%s",v["OldlCheatRate"].(string),v["NewlCheatRate"].(string),v["OldlCheatLimit"].(string),v["NewlCheatLimit"].(string))
			row["changlogs"] = str;
			row["reason"] = v["Reson"]
			list[k] = row
		}


		self.ajaxList("成功", MSG_OK, count, list)	
	} else if UserCkind == "2" {
	
		
		ret,_:= models.RecordCtrlDataTitle(strsql);

		list := make(map[string]interface{})
		if len(ret) >= 2{
			list["DATA1"] = ret[0];
			list["DATA2"] = ret[1];

		}
  		
		self.ajaxList("成功", MSG_OK, 0, list)	
	}
}
